package com.bear.cmcc.NetTestHTTP.ui.adapter;

import java.util.ArrayList;
import java.util.List;

import com.bear.cmcc.NetTestHTTP.R;
import com.bear.cmcc.NetTestHTTP.component.MenuBean;
import com.bear.cmcc.NetTestHTTP.util.MyCommonUtil;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MenuAdapter extends BaseAdapter {
	
	private List<MenuBean> list;
	private LayoutInflater inflater;
	private int sWidth;
	public MenuAdapter(Context context){
		this.inflater = LayoutInflater.from(context);
		this.list = new ArrayList<MenuBean>();
		this.sWidth = MyCommonUtil.getWindowWidth(context)/2;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public MenuBean getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return getItem(position).getId();
	}
	
	public void addObject(MenuBean b){
		list.add(b);
	}
	
	public void clear(){
		list.clear();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = inflater.inflate(R.layout.item_menu, null);
		RelativeLayout bglayout = (RelativeLayout)view.findViewById(R.id.itemMenu_bgLayout);
		TextView text = (TextView)view.findViewById(R.id.itemMenu_titleText);
		ImageView rightImage = (ImageView)view.findViewById(R.id.itemMenu_rightImage);
		bglayout.setMinimumWidth(sWidth);
		MenuBean b = getItem(position);
		
		if(position%2==0){
			rightImage.setVisibility(View.VISIBLE);
		}else{
			rightImage.setVisibility(View.INVISIBLE);
		}
		
		text.setText(b.getTitle());
		return view;
	}

}
